#pragma once
#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <log/log.h>
#include <stdlib.h>
#include "WmarkDev.h"
#include "IonDev.h"
#include <iostream>
#include "wmark_dev.h"
#include "ControlMsgIntface.h"

#define DMA_BUF_W      1280
#define DMA_BUF_H      960
#define DMA_BUF_CH     4
#define DMA_BUF_COUNT  4

#define WMARK_BUF_W     1280
#define WMARK_BUF_H     960
#define WMARK_BUF_CH    4
#define WMARK_BUF_COUNT 16

using camera::algorithm::ControlMsgIntface;

namespace android::wmark
{
    class BufManager : public ControlMsgIntface
    {
    public:
        BufManager(/* args */);
        ~BufManager();

        // 给 client-lib 发送消息，通知
        int sendNotify(uint8_t *srcBuf, uint64_t srcBufLen, wmark_buf_t &_info);

    private:
        WmarkDev *mWmarkDev = NULL;
        IonDev *mIonDev = NULL;

        std::mutex mutex;
        int mDmaBufArrayLen = 0; // dmabuf 数量， 也是 mDmaBufArray 数量
        struct ion_buffer_info *mDmaBufArray = NULL;
        int allocDmaInfo(int num);
        int deleteDmaInfo();

        int initDmaBuf(int num, int w, int h, int ch);
        int uninitDmaBuf();
        int initWmarkBuf(int num, int w, int h, int ch);

        void checkData(uint8_t *buf, uint64_t len);

        bool minitDmaFlag = false; // 表示 dma 是否初始化

        void onResult(control_msg_t &info) override;
    };
}
